package org.cttic.visualization.visualization.controller;

import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.cttic.visualization.visualization.cache.RedisService;
import org.cttic.visualization.visualization.util.GpsCoordinateUtils;
import org.cttic.visualization.visualization.util.ResponseObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 高速车辆实时位置汇总
 * @author zzo
 */
@RestController
@Slf4j
@RequestMapping(value = "/vehiclesLocation")
@CrossOrigin
public class RealLocationController {



    @RequestMapping(value = "/vehicles")
    public ResponseObject vehiclesLocation(){
        return null;

    }

   /* @Autowired
    private RedisService redisService;
    private ResponseObject v1(){
        log.info("****查询车辆坐标位置*****");
        ResponseObject responseObject = ResponseObject.success();
        JSONArray jsonList = redisService.getJSONList("freeflow809:");
        JSONArray response = new JSONArray();
        JSONObject cache = null;
        try {
            for (Object o : jsonList) {
                cache = new JSONObject(o);
                if (cache.isEmpty()) continue;
                if (cache.getStr("endLat") == null) continue;
                String vehicleNo = cache.getStr("vehicleNo");
                double longitude = cache.getDouble("longitude");
                double latitude = cache.getDouble("latitude");
                if (((int) latitude) == 0 || (int) longitude == 0) {
                    continue;
                }
                JSONObject newData = new JSONObject();
                double[] doubles = GpsCoordinateUtils.calWGS84toGC(longitude, latitude);
                newData.put("vehicleNo", vehicleNo);
                newData.put("coordinate", doubles);
                //newData.put("velocity", cache.getDouble("velocity") == null ? 0.0 : cache.getDouble("velocity"));
                response.add(newData);
            }
            responseObject.setBizBody(response);
            log.info("查询车辆实时位置结束");
            return responseObject;
        } catch (Exception e) {
            log.error("查询车辆实时位置异常{}" + e.getMessage());
            e.printStackTrace();
            return ResponseObject.error();
        }
    }*/



}
